#region Using

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using EstateNuke.Data;
using EstateNuke.Report;
using Gizmox.WebGUI.Common;
using Gizmox.WebGUI.Forms;
using EstateNuke.BusinessSystem.Categories.Report.EstateNukeCoreDBDataSetTableAdapters;
using Microsoft.Reporting.WebForms;

#endregion

namespace EstateNuke.BusinessSystem.Categories.Report.Controls
{
    public partial class FinancialDetailReportControl : EstateNukeControl
    {
        public FinancialDetailReportControl()
        {
            InitializeComponent();
            dtpFrom.Value = DateTime.Now.AddMonths(-1);
            dtpTo.Value = DateTime.Now;
            BindProject();
            this.reportViewer1.Visible = false;
        }

        private void BindProject()
        {
            cbbProject.Items.Clear();

            cbbProject.DisplayMember = "DisplayName";
            cbbProject.DataSource = CurrentProjects;
        }

        private void btnSearch_Click(object sender, EventArgs e)
        {
            if (cbbProject.SelectedItem != null)
            {
                this.reportViewer1.Visible = true;
                var project = cbbProject.SelectedItem as Project;

                this.reportViewer1.LocalReport.DataSources.Clear();

                EstateNukeCoreDBDataSet source = new EstateNukeCoreDBDataSet();

                FinancialContractDetailReportTableAdapter adapterLease = new FinancialContractDetailReportTableAdapter();
                adapterLease.Fill(source.FinancialContractDetailReport, dtpFrom.Value, dtpTo.Value, project.Id);

                FinancialLeaseContractDetailReportTableAdapter adapterCustomerCommunication = new FinancialLeaseContractDetailReportTableAdapter();
                adapterCustomerCommunication.Fill(source.FinancialLeaseContractDetailReport, dtpFrom.Value, dtpTo.Value, project.Id);

                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FinancialContractDetailDataSet", source.FinancialContractDetailReport.Copy()));
                this.reportViewer1.LocalReport.DataSources.Add(new ReportDataSource("FinancialLeaseContractDetailDataSet", source.FinancialLeaseContractDetailReport.Copy()));

                this.reportViewer1.CurrentPage = 1;
                this.reportViewer1.Update();
            }
        }

        private void reportViewer1_HostedPageLoad(object sender, Gizmox.WebGUI.Forms.Hosts.AspPageEventArgs e)
        {
            this.reportViewer1.ProcessingMode = Microsoft.Reporting.WebForms.ProcessingMode.Local;
            reportViewer1.LocalReport.ReportPath = "Categories/Report/RDLCs/FinancialContractDetailReport.rdlc";
        }
    }
}